//
//  HRCancelOrderView.m
//  haierapp
//
//  Created by Xia Zhiyong on 14-8-19.
//  Copyright (c) 2014年 haier. All rights reserved.
//

#import "HRCancelOrderView.h"

@interface HRCancelOrderView (){
    NSMutableArray *arrayTable;
    NSInteger currentSelect;
}
@end

@implementation HRCancelOrderView

- (id)initWithFrame:(CGRect)frame
{
    
    self = [[[NSBundle mainBundle] loadNibNamed:@"HRCancelOrderView"
                                          owner:self
                                        options:nil] objectAtIndex:0];


    
    return self;
}

-(void)loadTable{
    arrayTable = [[NSMutableArray alloc] initWithObjects:@"我不想买了",@"信息填写错误，重新换",@"商家缺货",@"其他原因", nil];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView reloadData];
}


-(NSString *)getCurrentSelectItem{
    NSString *selectItem=[arrayTable objectAtIndex:currentSelect];
    
    return selectItem;
}


#pragma mark - UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return arrayTable.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"cellIden";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    for (UIView *v in cell.contentView.subviews) {
        [v removeFromSuperview];
    }
    
    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 200, 30)];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.textColor = [UIColor colorFromHexRGB:@"303030"];
    lbl.text = [arrayTable objectAtIndex:indexPath.row];
    lbl.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:lbl];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(280, 5, 30, 30)];
    btn.tag = indexPath.row;
    [btn setImage:[UIImage imageNamed:@"btn_select_off"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"btn_radio_on"] forState:UIControlStateSelected];
    btn.selected = NO;
    if (currentSelect == indexPath.row) {
        btn.selected = YES;
    }
    [btn addTarget:self action:@selector(actionBtn:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:btn];
    
    return cell;
}

-(void)actionBtn:(UIButton*)btn{
    if (!btn.selected) {
        btn.selected = YES;
        currentSelect = btn.tag;
        [_tableView reloadData];
    }
}
@end
